#ifndef ZVIEWDEVICE_HPP
#define ZVIEWDEVICE_HPP

#include <vector>
#include "zviewctl.h"
#include <string>
#include <functional>
struct DevInfo;

class DeviceInfo
{
public:
    std::string  strName;         //设备名称
    std::string  strPath;         //设备文件路径
    std::string  strDisciptor;    //设备描述信息
    std::string  strId;           //设备辨识ID
    std::string  strType;         //设备类型描述
};



class IZViewDevice
{
public:
    virtual ~IZViewDevice(){};

    //常规
    virtual bool Open() =0;
    virtual bool IsOpen()=0;
    virtual bool Close() =0;

    //读写
    virtual bool Write(uint8_t bar,uint32_t offset,const void* data,uint32_t len) = 0;
    virtual bool Read(uint8_t bar,uint32_t offset, void* data,uint32_t len) = 0;
    virtual bool DmaH2C(void* dst,void* src,size_t size) = 0;
    virtual bool DmaC2H(void* dst,void* src,size_t size) = 0;
    virtual bool DmaH2CAsyn(void* dst,void*src,uint32_t size,std::function<void(uint64_t)>callback)= 0;
    virtual bool DmaC2HAsyn(void* dst,void*src,uint32_t size,std::function<void(uint64_t)>callback)= 0;


    virtual void UseMap(bool used)=0;                                       //设置是否使用内存映射 否则默认使用io读写
    virtual bool MapMem(const std::initializer_list<uint8_t>& list) = 0;    //映射对应内存空间
    virtual void* GetMapMemAddr(uint8_t bar)=0;                             //获取设备内存空间映射地址

    //中断
    virtual int WaitInt(zview_interrupt_id interrupt_code,uint32_t timeout) = 0;       //同步阻塞等待中断
    virtual bool GetInrTable(zview_device_int_table& int_table) = 0;                    //获取中断列表
    virtual uint64_t GetInrMask()  const = 0;                                           //获取中断号 | 0 无中断; 1的位置表示中断号

    //其他
    virtual int  GetDeviceFd ()  const = 0 ;        //获取文件句柄
};

struct DeviceTools
{
public:
       static  std::vector<DeviceInfo> GetDevInfos();
       static  IZViewDevice*            CreatDev(const DeviceInfo&);

};




struct CZViewDevice:public IZViewDevice
{
public:
    CZViewDevice(const DeviceInfo& info);
protected:
    DeviceInfo  m_iInfo;
};
























#endif // ZVIEWDEVICE_HPP
